<?php

$host="localhost"; 
$root="root"; 
$root_password="password"; 

$user="newuser";
$pass="newpass";
$dbname="newdb"; 
$table="domains";
$namecol="domainName";
$descriptioncol="description";
$timestampcol="dns_timestamp";

    try {
        $dbh = new PDO("mysql:host=$host", $root, $root_password);
        
        $createdb = "CREATE DATABASE IF NOT EXISTS $dbname";
        $createtable = "CREATE TABLE IF NOT EXISTS $dbname.$table (
                $namecol VARCHAR(100) NOT NULL, 
                $descriptioncol VARCHAR(256), 
                $timestampcol DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
                PRIMARY KEY ($namecol))";
        $createuser = "CREATE USER '$user'@'%' IDENTIFIED BY '$pass';
                GRANT ALL ON `$dbname`.* TO '$user'@'%';
                FLUSH PRIVILEGES;";
        $dbh->exec($createdb);
        $dbh->exec($createtable);
        $dbh->exec($createuser);
        $dbh = null;
    } catch (PDOException $e) {
        trigger_error("DB ERROR: ". $e->getMessage());
    }
?>
